package generalClasses;

import java.util.*;

public class MainServer extends Server {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	ArrayList<Server> localServersList;
	
	public ArrayList<Server> getLocalServersList() {
		return localServersList;
	}

	public void setLocalServersList(ArrayList<Server> localServersList) {
		this.localServersList = localServersList;
	}

	public MainServer(String name, String adress, int port, int type, int state, int region) 
	{
		super(name, adress, port, type, state, region);
		this.localServersList=new ArrayList<Server>();
	}
	
	public boolean addLocalServer(Server newLocalServer)
	{
		if (this.localServersList.add(newLocalServer))
		{
			return true;
		}
		return false;
	}

	public Server findServerRegion(int area) 
	{
		int temp=-1;
		for (int i = 0; i < localServersList.size(); i++) 
		{
			if ( (localServersList.get(i).getRegion()== area)&&(localServersList.get(i).getState()==ProgramData.ONLINE))
			{
				temp=i;
			}
		}
		
		if ( temp == -1)
		{
			return this;
		}	
		return localServersList.get(temp);
	}

}
